package org.dxj.restaurantmanagementsystem.service.impl;

import org.dxj.restaurantmanagementsystem.dao.IUserDao;
import org.dxj.restaurantmanagementsystem.dao.impl.UserDaoImpl;
import org.dxj.restaurantmanagementsystem.entity.User;
import org.dxj.restaurantmanagementsystem.service.IUserService;

import java.io.IOException;
import java.util.List;

/**
 * @author Ding
 * @date 2019/11/23 17:51
 */
public class UserServiceImpl implements IUserService {

    /**
     * 创建UserDao对象
     */
    IUserDao iUserDao=new UserDaoImpl();

    /**
     * 增加用户Service
     * @param user
     * @return boolean
     * @throws IOException
     */
    @Override
    public boolean insertUserService(User user) throws IOException {
     List<User> userList=iUserDao.selectUserByIdDao(user.getId());
     if (userList.size()==0){
         iUserDao.insertUserDao(user);
         return true;
     }else {
         return true;
     }
    }

    /**
     * 根据用户id删除用户信息Service
     * @param id
     * @return boolean
     */
    @Override
    public boolean deleteUserService(Integer id) throws IOException {
        iUserDao.deleteUserDao(id);
        return false;
    }

    /**
     * 根据用户id更改用户Service
     * @param user
     * @param id
     * @return boolean
     */
    @Override
    public boolean updateUserService(User user, Integer id) {
        return false;
    }

    /**
     * 根据用户id查询用户信息Service
     * @param id
     * @return List<User>
     * @throws IOException
     */
    @Override
    public List<User> selectUserByIdService(Integer id) throws IOException {
        List<User> list=iUserDao.selectUserByIdDao(2);
        for (int i = 0; i <list.size() ; i++) {
            System.out.println(list.get(i));
        }
        return null;
    }

    /**
     * 查询用户所有信息Service
     * @return List<User>
     * @throws IOException
     */
    @Override
    public List<User> selectUserService() throws IOException {
        List<User> list=iUserDao.selectUserByIdDao(2);
        for (int i = 0; i <list.size() ; i++) {
            System.out.println(list.get(i));
        }
        return null;
    }
}
